To
replay a trace, you must have a trace saved to a file or a table. The
trace must be captured with certain trace events to enable playback. The
required events are captured by default if you use the Profiler
template TSQL_Replay. You can define a
trace to be saved when you create or modify the trace definition. You
can also save the current contents of the trace window to a file or
table by using the Save As Trace File or Save As Trace Table options in
the File menu.
To replay a saved trace,
you choose File and then Open to open a trace file or trace table. After
you select the type of trace to replay, a grid with the trace columns
selected in the original trace is displayed. At this point, you can
either start the replay of the trace step-by-step or complete execution
of the entire trace. The options for replaying the trace are found under
the Replay menu. When you start the replay of the trace, the Connect to
Server dialog is displayed, enabling you to choose the server that you
want to replay the traces against. When you are connected to a server, a
Replay Configuration dialog like the one shown in Figure 1 is displayed.
The first replay option,
which is enabled by default, replays the trace in the same order in
which it was captured and allows for debugging. The second option takes
advantage of multiple threads; it optimizes performance but disables
debugging. A third option involves specifying whether to display the
replay results. You would normally want to see the results, but for
large trace executions, you might want to forgo displaying the results
and send them to an output file instead.
If you choose the option
that allows for debugging, you can execute the trace in a manner similar
to many programming tools. You can set breakpoints, step through
statements one at a time, or position the cursor on a statement within
the trace and execute the statements from the beginning of the trace to
the cursor position.
Note
Automating testing scripts is
another important use of the SQL Profiler Save and Replay options. For
instance, a trace of a heavy production load can be saved and rerun
against a new release of the database to ensure that the new release has
similar or improved performance characteristics and returns the same
data results. The saved traces can help make regression testing much
easier.
You also have the
option of specifying advanced replay options in SQL Server 2008. These
options are found on the Advanced Replay Options tab of the Replay
Configuration dialog (see Figure 2).
The
first two options on the Advanced Replay Options tab relate to the
system process IDs (SPIDs) targeted for replay. If the Replay System
SPIDs option is selected, the trace events for every SPID in the trace
file will be replayed. If you want to target activity for a specific
SPID, you should choose the Replay One SPID Only option and select the
SPID from the drop-down menu. You can also limit the events that will be
replayed based on the timing of the events. If you want to replay a
specific time-based section of the trace, you can use the Limit Replay
by Date and Time option. Only those trace events that fall between the
data range you specify will be replayed.
The last set of
advanced options is geared toward maintaining the health of the server
on which you are replaying the trace. The Health Monitor Wait Interval
(sec) option determines the amount of time a thread can run during
replay before being terminated. This helps avoid an excessive drain on
the server’s resources. The Health Monitor Poll Interval (sec) option
determines how often the health monitor will poll for threads that
should be terminated. The last advanced option on the screen relates to
blocked processes. When it is enabled, the monitor polls for blocked
processes according to the interval specified.